<style>
    .ivu-select, .ivu-input-wrapper, .ivu-cascader {
        width: 250px;
    }
</style>
<template>
    <div>
        <Divider id="invoice-id">特殊业务申请</Divider>
        <Card>
            <Form ref="formData" :model="formData" :rules="formRules" :label-width="250" inline>
                <FormItem label="申请编号">
                    <Input type="text" v-model="specialBusiness.applyNo" disabled/>
                </FormItem>
                <FormItem label="合作商">
                    <Input type="text" v-model="specialBusidisabledness.dealerName" disabled/>
                </FormItem>
                <FormItem label="客户姓名">
                    <Input type="text" v-model="specialBusiness.custName" disabled/>
                </FormItem>
                <FormItem label="证件号码">
                    <Input type="text" v-model="specialBusiness.certNo" disabled/>
                </FormItem>
                <FormItem label="申请时间">
                    <!--                    <Input type="date" v-model="formData.orderInfo.intoFirstDate" disabled/>-->
                    <DatePicker type="date" v-model="specialBusiness.intoFirstDate"
                                format="yyyy-MM-dd" disabled></DatePicker>
                </FormItem>
                <FormItem label="特殊原因" :required=true>
                    <Select v-model="specialBusiness.applyReason" filterable clearable>
                        <Option v-for="item in applyReasonDic" :value="item.value" :key="item.value"
                                :label="item.title">
                            {{ item.title }}
                        </Option>
                    </Select>
                </FormItem>
                <FormItem label="情况说明">
                    <Input type="textarea" v-model="specialBusiness.remarks"/>
                </FormItem>
            </Form>
            <div style="text-align: center;">
                <Button type="primary" @click="sumitSpecial" :loading="submitLoading" size="large"
                        style="width: 100px;">提交
                </Button>
                <Button type="primary" @click="cencalSpecial" size="large" style="width: 100px;">取消</Button>
            </div>
        </Card>
    </div>
</template>
<script>
    import {
        getSpecialPageInfo,
        sumitSpecial
    } from "_p/afs-apply/api/apply-contract/contract/special/specialBusiness";
    import {
        getEntryPageInfo
    } from "_p/afs-apply/api/apply-contract/contract/entry/contract-entry";
    import {getDictDataByType} from "_p/basic/api/admin/datadic";
    import {deepClone} from '@/libs/utils/ObjectClone';

    export default {
        data() {
            return {
                applyNo: "",
                submitLoading: false,
                formRules: {},
                custBaseInfo: {
                    certNo: "",
                },
                applyReasonDic: [],
                specialBusiness: {},
                formData: {
                    orderInfo: {
                        applyNo: "",
                        dealerName: "",
                    },
                    custBaseInfos: [],
                },
            }
        },
        mounted() {
            this.init();
        },
        methods: {
            init() {
                this.applyNo = this.afs.getPageParams(this).applyNo;
                this.initSelectData();
                this.getSpecialPageInfo();
            },
            getSpecialPageInfo() {
                getEntryPageInfo(this.applyNo).then(res => {
                    if (res.code === "0000") {
                        this.specialBusiness.applyNo = this.applyNo;
                        this.specialBusiness.dealerName = res.data.orderInfo.channelName;
                        this.specialBusiness.contractNo = res.data.contractInfo.contractNo;
                        this.specialBusiness.custName = res.data.orderInfo.custName;
                        res.data.custBaseInfos.forEach(e => {
                            if (e.custRole === "01") {
                                this.specialBusiness.certNo =e.certNo;
                            }
                        });
                        this.specialBusiness.intoFirstDate=res.data.contractInfo.lendingFirstDate;
                    }
                });
            },
            initSelectData() {
                //数据字典
                getDictDataByType("reason").then(res => {
                    if (res.code === "0000") {
                        this.applyReasonDic = deepClone(res.data);
                    }
                });
            },
            sumitSpecial() {
                if (!Object.prototype.hasOwnProperty.call(this.specialBusiness, "applyReason")) {
                    this.$Message.warning("请选择特殊原因");
                    return false;
                }
                this.specialBusiness.applyNo=this.applyNo;
                sumitSpecial(this.specialBusiness).then(res => {
                    if (res.code === "0000") {
                        this.submitLoading = false;
                        this.$Message.success(res.msg);
                        this.afs.closeTab(this);
                    } else {
                        this.submitLoading = false;
                        this.$Message.error(res.msg);
                    }
                }).catch(error => {
                    this.submitLoading = false;
                    this.$Message.error("功能维护中，请稍后重试");
                });

            },
            cencalSpecial() {
                this.afs.closeTab(this);
            }
        },
    }
</script>
